package handle

import (
	"strings"
)

type ConvH struct{}

func (h *ConvH) Hump(s string) *string {
	tmp := strings.Split(s, "_")
	var tar string
	for _, v := range tmp {
		if len(v) > 0 {
			tar += strings.Title(strings.ToLower(v))
		}
	}
	if len(tar) > 0 {
		return &tar
	} else {
		return nil
	}
}

func (h *ConvH) SqlType(s string) *string {
	var tar string
	if s == "varchar" {
		tar = "*string"
	} else if s == "int" {
		tar = "*int64"
	} else if s == "datetime" {
		tar = "*time.Time"
	} else if s == "float" || s == "double" || s == "decimal" {
		tar = "*float64"
	} else {
		return nil
	}
	return &tar
}

func (h *ConvH) sqlQuery(s []map[string]string) (map[string]*string, error) {
	insertKey := ""
	insertVal := ""
	for i, col := range s {
		if i == len(s)-1 {
			insertKey += col["column_name"] + "\n"
			insertVal += ":" + col["column_name"] + "\n"
		} else {
			insertKey += col["column_name"] + ", \n"
			insertVal += ":" + col["column_name"] + ", \n"
		}
	}
	tar := make(map[string]*string)
	tar["$INSERTKEY$"] = &insertKey
	tar["$INSERTVALUE$"] = &insertVal
	return tar, nil
}
